package com.fanfanwang.ffw.app.tools;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.annotation.SuppressLint;

@SuppressLint("SimpleDateFormat")
public class TimeUtils {
	public static final String FORMAT_YYYY_MM_DD = "yyyy-MM-dd";

	public static void main(String[] args) {
		System.out.println(getFormatDate("yyyy-MM-dd HH:mm:ss"));
	}

	/**
	 * @param format
	 *            指定的日期格式<br>
	 *            eg:<br>
	 *            "yyyy-MM-dd HH:mm:ss"<br>
	 *            "yyyy-MM-dd"<br>
	 *            "yyyyMMddHHmmss"<br>
	 *            "HH:mm:ss"<br>
	 * @return
	 */
	public static String getFormatDate(String format) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		Date date = new Date();
		return simpleDateFormat.format(date);
	}

	/**
	 * 获得当前日期时间
	 * 
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String getFormatDate1() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		return simpleDateFormat.format(date);
	}

	/**
	 * 获得当前日期时间
	 * 
	 * @return yyyyMMddHHmmss
	 */
	public static String getFormatDate2() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
		return simpleDateFormat.format(date);
	}

	public static String getCurrentFormatDate() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
		Date date = new Date();
		return simpleDateFormat.format(date);
	}

	/**
	 * 将日期格式 yyyy-M-d 转化为yyyyMMdd
	 * 
	 * @param date
	 *            yyyy-M-d
	 * @return yyyyMMdd
	 */
	public static String getFormatDate3(String date) {

		String year = date.split("-")[0];
		String month = date.split("-")[1];
		String day = date.split("-")[2];
		if (month.length() == 1) {
			month = "0" + month;
		}
		if (day.length() == 1) {
			day = "0" + day;
		}
		return year + month + day;

	}

	/**
	 * 将日期格式 yyyyMMdd 转化为 yyyy-MM-dd
	 * 
	 * @param date
	 *            yyyyMMdd
	 * @return yyyy-MM-dd
	 */
	public static String getFormatDate4(String date) {
		String year = date.substring(0, 4);
		String month = date.substring(4, 6);
		String day = date.substring(6, 8);
		return year + "-" + month + "-" + day;
	}

	/**
	 * 将日期格式 YYYYMMDDHHMMSS 转化为 YYYY-MM-DD HH:MM:SS
	 * 
	 * @param date
	 *            YYYYMMDDHHMMSS
	 * @return YYYY-MM-DD HH:MM:SS
	 */
	public static String getFormatDate5(String date) {
		String year = date.substring(0, 4);
		String month = date.substring(4, 6);
		String day = date.substring(6, 8);
		String hour = date.substring(8, 10);
		String min = date.substring(10, 12);
		String sec = date.substring(12, 14);
		return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
	}

	/**
	 * 获得当前时间
	 * 
	 * @return HH:mm
	 */
	public static String getFormatTime1() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
		Date date = new Date();
		return simpleDateFormat.format(date);
	}

	/**
	 * 获得当前时间
	 * 
	 * @return HH:mm:ss
	 */
	public static String getFormatTime2() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
		Date date = new Date();
		return simpleDateFormat.format(date);
	}

	/**
	 * 将时间格式 HH:mm 转化为 HHmm
	 * 
	 * @param addtime
	 *            HH:mm
	 * @return HHmm
	 */
	public static String getFormatTime3(String time) {
		return time.replaceAll(":", "");
	}

	/**
	 * 将时间格式 HHmm 转化为 HH:mm
	 * 
	 * @param time
	 *            HHmm
	 * @return HH:mm
	 */
	public static String getFormatTime4(String time) {
		String hour = "00";
		String min = "00";
		if (time.length() == 4) {
			hour = time.substring(0, 2);
			min = time.substring(2, 4);
		}
		return hour + ":" + min;
	}

	/**
	 * 传入时间戳 精确到毫秒
	 * 
	 * @param time
	 * @return
	 * @throws Exception
	 */
	public static String getDate(String time) throws Exception {
		long da = Long.valueOf(time);
		Date date = new Date(da);
		SimpleDateFormat sDate = new SimpleDateFormat("yyyy年MM月dd日");
		String values = sDate.format(date);
		return values;
	}

	/**
	 * 传入时间戳 精确到毫秒
	 * 
	 * @param time
	 * @return
	 * @throws Exception
	 */
	public static String getDate11(String time) throws Exception {
		long da = Long.valueOf(time);
		Date date = new Date(da);
		SimpleDateFormat sDate = new SimpleDateFormat("yy年MM月dd日");
		String values = sDate.format(date);
		return values;
	}

	/**
	 * 传入时间戳 精确到毫秒
	 * 
	 * @param time
	 * @return
	 * @throws Exception
	 */
	public static String getDate(long time) throws Exception {
		Date date = new Date(time);
		SimpleDateFormat sDate = new SimpleDateFormat("yyyy年MM月dd日");
		String values = sDate.format(date);
		return values;
	}

	/**
	 * 传入时间戳 精确到毫秒
	 * 
	 * @param time
	 * @return
	 * @throws Exception
	 */
	public static String getDate1(String time) throws Exception {
		long da = Long.valueOf(time);
		Date date = new Date(da);
		SimpleDateFormat sDate = new SimpleDateFormat("yyyy.MM.dd");
		String values = sDate.format(date);
		return values;
	}

	/**
	 * 传入时间戳 精确到毫秒
	 * 
	 * @param time
	 * @return
	 * @throws Exception
	 */
	public static String getDateYYYYMMDD(String time) throws Exception {
		long da = Long.valueOf(time);
		Date date = new Date(da);
		SimpleDateFormat sDate = new SimpleDateFormat("yyyyMMdd");
		String values = sDate.format(date);
		return values;
	}

	/**
	 * 根据指定的时间戳，返回指定格式的日期时间
	 * 
	 * @param timeStr
	 *            时间戳
	 * @param formatType
	 *            指定的日期格式<br>
	 *            eg:<br>
	 *            "yyyy-MM-dd HH:mm:ss"<br>
	 *            "yyyy-MM-dd"<br>
	 *            "yyyyMMddHHmmss"<br>
	 *            "HH:mm:ss"<br>
	 * @return
	 */
	public static String getFormatTime(long time, String format) {
		Date date = new Date(time);
		String strs = "";
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			strs = sdf.format(date);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strs;

	}

	/**
	 * @param day
	 *            输入日期格式 yyyy-MM-dd
	 * @leaveDay 差距的天数 -1 or +1
	 * @return 获取指定日期往前或者往后几天的日期
	 */
	public static String getFormatLeaveDay(String day, int leaveDay) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		;
		Date date = null;
		try {
			date = simpleDateFormat.parse(day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);

		calendar.add(Calendar.DATE, leaveDay);
		date = calendar.getTime();
		return simpleDateFormat.format(date);
	}

	/**
	 * @param day
	 *            输入日期格式 yyyy-MM-dd
	 * @return 获得前一天的日期
	 */
	public static String getFormatBeforeDay(String day) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = simpleDateFormat.parse(day);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, -1); // 得到前一天
		date = calendar.getTime();
		return simpleDateFormat.format(date);
	}

	/**
	 * @param day
	 *            输入日期格式 yyyy-MM-dd
	 * @return 获得后一天的日期
	 */
	public static String getFormatNextDay(String day) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = simpleDateFormat.parse(day);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, +1); // 得到后一天
		date = calendar.getTime();
		return simpleDateFormat.format(date);
	}

	/**
	 * 获得输入日期的星期
	 * 
	 * @param inputDate
	 *            需要转换的日期 yyyy-MM-dd
	 * @return 星期×
	 */
	public static String getWeekDay(String inputDate) {
		// String weekStrArr1[] = {"周日","周一","周二","周三","周四","周五","周六"};
		String weekStrArr1[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = simpleDateFormat.parse(inputDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int outWeek = calendar.get(Calendar.DAY_OF_WEEK);// 返回的是1-7的整数，1为周日，2为周一，以此类推。
		return weekStrArr1[outWeek - 1];
	}

	/**
	 * 检测时间是否在某个时间段内
	 * 
	 * @param timeSlot
	 *            时间段 00：00--24：00
	 * @param time
	 *            需要检测的时间 00：23
	 * @return
	 */
	public static boolean isInsideTime(String timeSlot, String time) {
		String startTime = timeSlot.split("--")[0];
		String endTime = timeSlot.split("--")[1];
		boolean isGreaterStart = compareTime(time, startTime);
		boolean isLessEnd = compareTime(endTime, time);
		if (isGreaterStart && isLessEnd) {
			return true;
		}
		return false;
	}

	/**
	 * 比较两个时间的大小
	 * 
	 * @param time1
	 *            00：23
	 * @param time2
	 *            00：25
	 * @return time1大于等于time2 为 true,time1小于time2 为 false
	 */
	public static boolean compareTime(String time1, String time2) {
		if (time1.equals("24:00") || time2.equals("00:00")) {
			return true;
		}
		if (time2.equals("24:00") || time1.equals("00:00")) {
			return false;
		}
		// DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		DateFormat df = new SimpleDateFormat("HH:mm");
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		try {
			c1.setTime(df.parse(time1));
			c2.setTime(df.parse(time2));
		} catch (java.text.ParseException e) {
			System.err.println("格式不正确");
		}
		int result = c1.compareTo(c2);

		if (result < 0) {
			return false;
		} else if (result >= 0) {
			return true;
		}
		return true;
	}
	/**
	 * 比较两个日期的大小
	 * 
	 * @param date1
	 *            2012-5-11
	 * @param date2
	 *            2012-5-11
	 * @return date1大于date2 为 true,date1小于等于date2 为 false
	 */
	public static boolean compareDate2(String date1, String date2,String format) {
		DateFormat df = new SimpleDateFormat(format);
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		try {
			c1.setTime(df.parse(date1));
			c2.setTime(df.parse(date2));
		} catch (java.text.ParseException e) {
			System.err.println("格式不正确");
		}
		int result = c1.compareTo(c2);

		if (result <= 0) {
			return false;
		} else if (result > 0) {
			return true;
		}
		return true;
	}

	/**
	 * 比较两个日期的大小
	 * 
	 * @param date1
	 *            2012-5-11
	 * @param date2
	 *            2012-5-11
	 * @return date1大于等于date2 为 true,date1小于date2 为 false
	 */
	public static boolean compareDate(String date1, String date2,String format) {
		DateFormat df = new SimpleDateFormat(format);
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		try {
			c1.setTime(df.parse(date1));
			c2.setTime(df.parse(date2));
		} catch (java.text.ParseException e) {
			System.err.println("格式不正确");
		}
		int result = c1.compareTo(c2);

		if (result < 0) {
			return false;
		} else if (result >= 0) {
			return true;
		}
		return true;
	}

	// 将字符串转为时间戳
	public static String getTime(String user_time) {

		return getTime(user_time, "yyyy年MM月dd日");
	}

	// 将字符串转为时间戳
	public static String getTime(String user_time, String format) {
		String re_time = null;
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date d;
		try {

			d = sdf.parse(user_time);
			long l = d.getTime();
			re_time = String.valueOf(l);

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return re_time;
	}

	/**
	 * 根据客户要求格式化时间
	 * 
	 * @param time
	 * @return
	 */
	public static String formatCustomTime(String time, int type) {
		if (time == null) {
			return "";
		}
		if (time.contains("."))
			time = time.substring(0, time.indexOf(".") - 1);
		System.out.println("time----" + time);
		Date afterDate = new Date();
		long beforeTime = Long.parseLong(time);
		Date beforeDate = new Date(beforeTime);
		String formatTime = null;
		long difference = System.currentTimeMillis() - beforeTime;
		if (difference < 3600000)
			if (type == 0)
				formatTime = "今天";
			else
				formatTime = difference / 60000 + "分钟前";
		else if (3600000 < difference && difference < 86400000)
			if (type == 0)
				formatTime = "今天";
			else
				formatTime = difference / 3600000 + "小时前";
		else if (86400000 < difference && difference < 172800000)
			formatTime = "昨天";
		else if (172800000 < difference && difference < 259200000)
			formatTime = "前天";
		else if (259200000 < difference && difference < 604800000)
			formatTime = "本周" + getWeek(beforeDate);
		else if (604800000 < difference && difference < 1209600000)
			formatTime = "上周" + getWeek(beforeDate);
		else {
			if (beforeDate.getYear() == afterDate.getYear()) {
				SimpleDateFormat sDate = new SimpleDateFormat("MM月dd日");
				formatTime = sDate.format(beforeDate);
			} else {
				SimpleDateFormat sDate = new SimpleDateFormat("yyyy年MM月dd日");
				formatTime = sDate.format(beforeDate);
			}
		}
		return formatTime;
	}

	/**
	 * 格式化时间格式
	 * 
	 * @param time
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public static String formatTimeString(String time) {
		Date afterDate = new Date();
		long beforeTime = Long.valueOf(time);
		Date beforeDate = new Date(beforeTime);
		if (beforeDate.getYear() == afterDate.getYear()) {
			if (beforeDate.getDate() == afterDate.getDate() && beforeDate.getMonth() == afterDate.getMonth()) {
				return "今天";
			} else if (beforeDate.getDate() != afterDate.getDate() && beforeDate.getMonth() == afterDate.getMonth()) {
				if ((beforeDate.getDate() + 1) == afterDate.getDate())
					return "昨天";
				else if ((beforeDate.getDate() + 2) == afterDate.getDate())
					return "前天";
				else if (afterDate.getDay() - beforeDate.getDate() <= 7)
					return "本周" + getWeek(beforeDate);
				else if (afterDate.getDay() - beforeDate.getDate() > 7 && afterDate.getDay() - beforeDate.getDate() <= 14)
					return "上周" + getWeek(beforeDate);
				else {
					SimpleDateFormat sDate = new SimpleDateFormat("MM月dd日");
					String values = sDate.format(beforeDate);
					return values;
				}
			} else {
				SimpleDateFormat sDate = new SimpleDateFormat("MM月dd日");
				String values = sDate.format(beforeDate);
				return values;
			}
		} else {
			SimpleDateFormat sDate = new SimpleDateFormat("yyyy年MM月dd日");
			String values = sDate.format(beforeDate);
			return values;
		}
	}

	/**
	 * 将时间戳转换成"yyyy-M-dd"日期格式
	 * 
	 * @param time
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public static String formatTimeString1(String time) {
		Date afterDate = new Date();
		long beforeTime = Long.valueOf(time);
		Date beforeDate = new Date(beforeTime);

		SimpleDateFormat sDate = new SimpleDateFormat("yyyy-M-dd");
		String values = sDate.format(beforeDate);
		return values;

	}

	/**
	 * 将返回的时间戳转换成"yyyy年M月dd日"日期格式
	 * 
	 * @param time
	 * @return
	 */
	public static String formatTimeString2(String time) {
		Date afterDate = new Date();
		long beforeTime = Long.valueOf(time);
		Date beforeDate = new Date(beforeTime);

		SimpleDateFormat sDate = new SimpleDateFormat("yyyy年M月dd日");
		String values = sDate.format(beforeDate);
		return values;

	}

	private static Calendar cal = Calendar.getInstance();
	private static Calendar current;
	private static SimpleDateFormat sDate;

	/**
	 * 格式化日期为 今天、昨天、前天、本周、上周……
	 * 
	 * @param str
	 * @return
	 */
	public static String getDateString(String str) {
		Date fromdate = null;
		Date currentDate = null;
		String temp = "";
		try {
			fromdate = stringToDate(str);
			cal.setTime(fromdate);
			cal.set(Calendar.HOUR_OF_DAY, 0);
			cal.set(Calendar.MINUTE, 0);
			current = Calendar.getInstance();
			current.set(Calendar.HOUR_OF_DAY, 0);
			current.set(Calendar.MINUTE, 0);
			currentDate = current.getTime();
			int chineseWeek_current = getChineseWeek(current);
			int lastweekNum = chineseWeek_current + 7;
			int dateCha = getGapCount(fromdate, currentDate);
			if (dateCha < 0) {
				sDate = new SimpleDateFormat("yyyy年MM月dd日");
				temp = sDate.format(cal.getTime());
			} else if (dateCha == 0) {
				temp = "今天";
			} else if (dateCha == 1) {
				temp = "昨天";
			} else if (dateCha == 2) {
				temp = "前天";
			} else if (2 < dateCha && dateCha < chineseWeek_current) {// 本周
				temp = "本周" + getWeek(cal.getTime());
			} else if (dateCha >= chineseWeek_current && dateCha < lastweekNum) {// 可能为上一周或者
																					// 月日
				temp = "上周" + getWeek(cal.getTime());
			} else {
				if (cal.get(Calendar.YEAR) == current.get(Calendar.YEAR)) {
					sDate = new SimpleDateFormat("MM月dd日");
					temp = sDate.format(cal.getTime());
				} else {
					sDate = new SimpleDateFormat("yyyy年MM月dd日");
					temp = sDate.format(cal.getTime());
				}
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		/*
		 * if (hours <= 0) { temp = "今天"; } else if (hours <= 24) { temp = "昨天";
		 * } else if (hours <= 48) { temp = "前天"; } else if (hours / 24 <
		 * chineseWeek_current) {// 本周 temp = "本周" + getWeek(cal.getTime()); }
		 * else if (hours / 24 < lastweekNum) {// 可能为上一周或者 月日 temp = "上周" +
		 * getWeek(cal.getTime()); } else { if (cal.get(Calendar.YEAR) ==
		 * current.get(Calendar.YEAR)) { sDate = new SimpleDateFormat("MM月dd日");
		 * temp = sDate.format(cal.getTime()); } else { sDate = new
		 * SimpleDateFormat("yyyy年MM月dd日"); temp = sDate.format(cal.getTime());
		 * } }
		 */
		return temp;
	}

	/**
	 * 将传过来的“20131119”转换成“2013年11月19日”
	 * 
	 * @param str
	 * @return
	 */
	public static String getDateString1(String str) {
		Date fromdate = null;
		Date currentDate = null;
		String temp = "";
		try {
			fromdate = stringToDate(str);
			cal.setTime(fromdate);
			cal.set(Calendar.HOUR_OF_DAY, 0);
			cal.set(Calendar.MINUTE, 0);
			current = Calendar.getInstance();
			current.set(Calendar.HOUR_OF_DAY, 0);
			current.set(Calendar.MINUTE, 0);
			currentDate = current.getTime();

			sDate = new SimpleDateFormat("yyyy年MM月dd日");
			temp = sDate.format(cal.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return temp;
	}

	public static Date stringToDate(String str) throws ParseException {
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
		Date date = df.parse(str);
		return date;
	}

	/**
	 * 获取两个日期之间时间差毫秒级
	 * 
	 * @return
	 */
	public static long getTimeCountLong(String startDate, String endDate) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date d1 = df.parse(startDate);
			
			Date d2 = df.parse(endDate);
			long diff = d1.getTime() - d2.getTime();//这样得到的差值是微秒级别
			return diff;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	/**
	 * 获取两个日期之间时间差（倒计时）
	 * 
	 * @return
	 */
	public static String getTimeCount(String startDate, String endDate) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = "";
		try
		 
		{
//		  Date d1 = df.parse(startDate);
//			 
//		  Date d2 = df.parse(endDate);
//		  
//		  long diff = d1.getTime() - d2.getTime();//这样得到的差值是微秒级别
//		  
		  long diff = getTimeCountLong(startDate, endDate);
		  long days = diff / (1000 * 60 * 60 * 24);
		 
		  long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
		  long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
		  long second = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60) - minutes*(1000*60))/1000;
		  System.out.println(""+days+"天"+hours+"小时"+minutes+"分"+second+"秒");
		  time = ""+days+"天"+hours+"小时"+minutes+"分"+second+"秒";
		}
		catch (Exception e)
		{
		}
		return time;
	}
	/**
	 * 获取两个日期之间时间差（倒计时）
	 * 
	 * @return
	 */
	public static String getTimeCount(long diff) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = "";
		try
		
		{
			long days = diff / (1000 * 60 * 60 * 24);
			
			long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
			long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
			long second = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60) - minutes*(1000*60))/1000;
//			System.out.println(""+days+"天"+hours+"小时"+minutes+"分"+second+"秒");
			time = ""+days+"天"+hours+"小时"+minutes+"分"+second+"秒";
		}
		catch (Exception e)
		{
		}
		return time;
	}
	/**
	 * 获取两个日期之间的间隔天数
	 * 
	 * @return
	 */
	public static int getGapCount(Date startDate, Date endDate) {
		Calendar fromCalendar = Calendar.getInstance();
		fromCalendar.setTime(startDate);
		fromCalendar.set(Calendar.HOUR_OF_DAY, 0);
		fromCalendar.set(Calendar.MINUTE, 0);
		fromCalendar.set(Calendar.SECOND, 0);
		fromCalendar.set(Calendar.MILLISECOND, 0);

		Calendar toCalendar = Calendar.getInstance();
		toCalendar.setTime(endDate);
		toCalendar.set(Calendar.HOUR_OF_DAY, 0);
		toCalendar.set(Calendar.MINUTE, 0);
		toCalendar.set(Calendar.SECOND, 0);
		toCalendar.set(Calendar.MILLISECOND, 0);

		return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24));
	}

	private static int getChineseWeek(Calendar cal) {
		int chineseWeek = (cal.get(Calendar.DAY_OF_WEEK) + 6) % 7;
		if (chineseWeek == 0) {
			chineseWeek = 7;
		}
		return chineseWeek;
	}

	private static String getWeek(Date date) {
		String week = null;
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		switch (c.get(Calendar.DAY_OF_WEEK)) {
		case 1:
			week = "日";
			break;
		case 2:
			week = "一";
			break;
		case 3:
			week = "二";
			break;
		case 4:
			week = "三";
			break;
		case 5:
			week = "四";
			break;
		case 6:
			week = "五";
			break;
		case 7:
			week = "六";
			break;
		default:
			break;
		}
		return week;
	}
	/**
	 * 将字符串转为时间戳  以秒为单位。
	 * @param time 日期字符串
	 * @param format  格式"yyyy-MM-dd HH:mm:ss"
	 * yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	public static long parseDateToLong(String time,String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date = new Date();
		try{
			date = sdf.parse(time);
		} catch(ParseException e) {
			e.printStackTrace();
		}
		return date.getTime()/1000;
	}
	
	
	
	/**
	 * 将时间戳转为时间  以秒为单位。
	 * @param time 时间戳
	 * @param format  格式"yyyy-MM-dd HH:mm:ss"
	 * yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	public static String parseLongToDate(String time, String format) {
		long l=Long.parseLong(time);
		Date date = new Date(l*1000);
		String strs = "";
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			strs = sdf.format(date);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strs;

	}

}
